<?php
namespace App\Traits;
trait ActionButtonTrait{
	
	public function getShowActionButton($parentUrl){
		$thisUrl = $parentUrl.'.'.config('admins.globals.route_rule.show');
		if(sp_check_auth($thisUrl)){
			return '<a class="btn btn-info btn-xs" href="'.route($thisUrl,['id'=>$this->id]).'"><i class="fa fa-edit"></i> 查看</a> ';
		}
		return '';
  	}
	
	public function getEditActionButton($parentUrl)
	{
		$thisUrl = $parentUrl.'.'.config('admins.globals.route_rule.edit');
		if(sp_check_auth($thisUrl)){
			return '<a class="btn btn-warning btn-xs" href="'.route($thisUrl,['id'=>$this->id]).'"><i class="fa fa-edit"></i> 修改</a> ';
		}
		return '';
	}
	
	public function getDestroyActionButton($parentUrl)
	{
		$thisUrl = $parentUrl.'.'.config('admins.globals.route_rule.destroy');
		if(sp_check_auth($thisUrl)){
			return '<a class="btn btn-danger btn-xs destroy_item" href="javascript:;"><i class="fa fa-edit"></i> 删除<form action="'
					.route($thisUrl,['id'=>$this->id]).'" method="POST" style="display:none">
					<input type="hidden" name="_method" value="delete"><input type="hidden" name="_token" value="'.csrf_token()
					.'"></form></a> ';
		}
		return '';
	}

	public function getListActionButton($currentRouteName)
	{
		$pointPost = strrpos($currentRouteName,'.');
		$parentUrl = substr($currentRouteName,0,$pointPost);
	    return $this->getShowActionButton($parentUrl).
	            $this->getEditActionButton($parentUrl).  
	            $this->getDestroyActionButton($parentUrl);
	}
}
